package com.ztom.context.support.event.multicast

import com.ztom.beans.factory.BeanFactory
import com.ztom.beans.factory.support.aware.BeanFactoryAware
import com.ztom.context.support.event.event.ApplicationEvent
import com.ztom.context.support.event.listener.ApplicationListener

/**
 * @author ZhangTao
 */
abstract class AbstractApplicationEventMulticaster: ApplicationEventMulticaster, BeanFactoryAware {

    protected val applicationListeners = HashSet<ApplicationListener<ApplicationEvent>>()

    private var beanFactory: BeanFactory? = null

    @Suppress("UNCHECKED_CAST")
    override fun addApplicationListener(listener: ApplicationListener<*>) {
        applicationListeners.add(listener as ApplicationListener<ApplicationEvent>)
    }

    override fun removeApplicationListener(listener: ApplicationListener<*>) {
        applicationListeners.remove(listener)
    }

    override fun setBeanFactory(beanFactory: BeanFactory) {
        this.beanFactory = beanFactory
    }
}